﻿using SpyApp.Models.EntytiRepossitory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace SpyApp.Models
{
    public class RolesExt
    {
        public static IEnumerable<Roles> GetAllRoles(UserRepository _userRepository = null, List<Roles> _valueIfNull = null)
        {
            try
            {
                if (_userRepository == null) _userRepository = new UserRepository();
                return _userRepository.GetAllRoles();
            }
            catch
            {
                return _valueIfNull;
            }
        }

        //public static IEnumerable<Roles> GetListRoleByUserId(string _userId, UserRepository _userRepository = null, List<Roles> _valueIfNull = null)
        //{
        //    try
        //    {
        //        if (_userRepository == null) _userRepository = new UserRepository();
        //        return _userRepository.GetRolesByUser(_userId);
        //    }
        //    catch
        //    {
        //        return _valueIfNull;
        //    }
        //}

        public static List<Roles> GetListRoleByListId(List<string> _listRoleId, UserRepository _userRepository = null, List<Roles> _valueIfNull = null)
        {
            try
            {
                if (_userRepository == null) _userRepository = new UserRepository();

                List<Roles> listRole = new List<Roles>();
                foreach (var roleId in _listRoleId)
                {
                    Roles role = _userRepository.GetRoleById(roleId);
                    listRole.Add(role);
                }
                return listRole;
            }
            catch
            {
                return _valueIfNull;
            }
        }
    }
}
